
/* TODO 使用STL实现MAP */

#ifndef VANTIDEL_CPP_OBJMAP_H
#define VANTIDEL_CPP_OBJMAP_H

#include "ObjHeader.h"

#define MAP_LOAD_PERCENT 0.8

typedef struct {
    Value key;
    Value value;
} Entry;   //key->value 键值对

class ObjMap {
public:
    ObjHeader objHeader;
    uint32_t capacity = 0; //Entry的容量(即总数),包括已使用和未使用Entry的数量
    uint32_t count = 0;  //map中使用的Entry的数量
    Entry *entries = nullptr; //Entry数组

    explicit ObjMap(VM *vm);

    ObjMap *NewObjMap(VM *vm);

    static void MapSet(VM *vm, ObjMap *objMap, Value key, Value value);

    static Value MapGet(ObjMap *objMap, Value key);

    static void ClearMap(VM *vm, ObjMap *objMap);

    static Value RemoveKey(VM *vm, ObjMap *objMap, Value key);

};


#endif //VANTIDEL_CPP_OBJMAP_H
